package com.example.wanbaqian.utils;

import android.text.TextUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/4/15 0015.
 * 时间工具类
 */

public class TimeUtils {

    public static String getCurrentTimeByFormat() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        Date curDate = new Date(System.currentTimeMillis());
        return formatter.format(curDate);
    }
    public static String getCurrentTimeByFormat(String formatStr) {
        SimpleDateFormat formatter = new SimpleDateFormat(TextUtils.isEmpty(formatStr) ? "yyyyMMddHHmmss" : formatStr);
        Date curDate = new Date(System.currentTimeMillis());
        return formatter.format(curDate);
    }

    public static String getCurrentTimeByFormat(long time) {
        SimpleDateFormat formatter = new SimpleDateFormat("MM月dd日");
        Date curDate = new Date(time);
        return formatter.format(curDate);
    }

    // 将时间戳转为字符串
    public static String getStrTime(String time, String formatStr) {
        return new SimpleDateFormat(TextUtils.isEmpty(formatStr) ? "yyyy/MM/dd" : formatStr).format(new Date(Long.valueOf(time) * 1000L));
    }

    /**
     * 返回格式 2017年7月
     * @param time
     * @return
     */
    public static String getStringData(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy年MM月");
        @SuppressWarnings("unused")
        long lcc = Long.valueOf(time);
        String times = sdr.format(new Date(lcc * 1000L));
        return times;
    }

    public static String getStringnumber(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("dd");
        @SuppressWarnings("unused")
        long lcc = Long.valueOf(time);
        String times = sdr.format(new Date(lcc * 1000L));
        return times;
    }

    public static String getDecadeTimestamp() {
        long time = System.currentTimeMillis();
        String str = String.valueOf(time);
        return str;


    }
}
